package kodkod.analysis;

import java.text.DecimalFormat;
import java.text.NumberFormat;

import kodkod.ast.*;
import kodkod.analysis.*;

public class LeafInfo implements Comparable<LeafInfo> {
	
	public LeafExpression leaf;	
	public int index = -1;
	public double weight = 0.0;
	
	public LeafInfo(LeafExpression node, int index) {
		this.leaf = node;
		this.index = index;
	}
	
	public double getWeight() {
		return weight;
	}
	
	@Override
	public boolean equals(Object o) {
		return o instanceof LeafInfo ? ((LeafInfo)o).leaf == leaf : false;
	}

	@Override
	public int compareTo(LeafInfo o) {
		return Math.round(10000 * (o.getWeight() - getWeight())) != 0 ? (int)Math.round(10000 * (o.getWeight() - getWeight())) : index - o.index;
	}
	
	@Override
	public String toString() {
		NumberFormat format = new DecimalFormat("#0.000");
		return index + " " + leaf + " (" + " weight: " + format.format(getWeight()) + ")";
	}
}
